﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace Improve157
{
   public  class Chapter_04
    {

        public void Suggestion_46()
        {

        }

        public void Suggestion_55()
        {
            Person mike = new Person() { Age = 21 ,Name ="Mike"};
            BinaryFormatter formatter = new BinaryFormatter();

            System.Runtime.Serialization.OnDeserializedAttribute onDeserializedAttribute = new System.Runtime.Serialization.OnDeserializedAttribute();

            //System.Runtime.Serialization.OnDeserializingAttribute;


            //System.Runtime.Serialization.OnSerializedAttribute

            //System.Runtime.Serialization.OnSerializingAttribute
        }
        
    }

    public class DisposeDemo : IDisposable
    {

        private IntPtr nativeResource = Marshal.AllocHGlobal(100);
        //private AnotherResource managedResource = new AnotherResource();

        private bool disposed = false;


        public void Dispose()
        {
            Dispose(true);

            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// 非必要,为了更符合其他语言
        /// </summary>
        public void Close()
        {
            Dispose();
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }
            if (disposing)
            {

            }
        }

        public void SamplePublicMethod()
        {

        }

        ~DisposeDemo()
        {
            Dispose(false);
        }
    }

    [Serializable]
    class Person
    {
        [NonSerialized]
        private string name;
        public int Age { get; set; }

        public string  Name { get; set; }

        [field:NonSerialized]
        public event Action Event_Event1;
    }

}
